package com.example.zg.learn.customView;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

/**
 * 描述：掉落的小球
 * zhougan
 * 2019/1/20
 **/
public class DownView extends View {
    private float r=40;//半径
    private float x;//不变
    private float y=r;//递增
    private Paint paint;


    public DownView(Context context) {
        super(context);
    }

    public DownView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DownView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DownView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private void initPaint(){
        if(paint==null){
            paint=new Paint(Paint.ANTI_ALIAS_FLAG);
            paint.setStrokeWidth(2);
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.FILL);
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        initPaint();
        if(x==0){
            x=getWidth()/2;
        }

        canvas.drawCircle(x,y,r,paint);
    }

    private void startAnimator(){
//        ValueAnimator valueAnimator=ValueAnimator.ofArgb(r,);
    }
}
